package com.smcs.idcmanager.service.impl;

import java.util.ArrayList;
import java.util.List;

import org.hi.SpringContextHolder;
import org.hi.framework.paging.PageInfo;
import org.hi.framework.service.impl.ManagerImpl;

import com.smcs.idcmanager.dao.IdcDAO;
import com.smcs.idcmanager.model.Domain;
import com.smcs.idcmanager.model.GatewayInfo;
import com.smcs.idcmanager.model.HouseInfo;
import com.smcs.idcmanager.model.HousesHoldInfo;
import com.smcs.idcmanager.model.HousesHoldInfo2;
import com.smcs.idcmanager.model.Idc;
import com.smcs.idcmanager.model.IdcUserInfo;
import com.smcs.idcmanager.model.Idc_manager_user;
import com.smcs.idcmanager.model.InternetIp;
import com.smcs.idcmanager.model.Ipseg;
import com.smcs.idcmanager.model.IpsegInfo;
import com.smcs.idcmanager.model.Iptrans;
import com.smcs.idcmanager.model.NetIp;
import com.smcs.idcmanager.model.OtherUser;
import com.smcs.idcmanager.model.ServiceContent;
import com.smcs.idcmanager.model.ServiceInfo;
import com.smcs.idcmanager.model.ServiceUser;
import com.smcs.idcmanager.service.DomainManager;
import com.smcs.idcmanager.service.GatewayInfoManager;
import com.smcs.idcmanager.service.HouseInfoManager;
import com.smcs.idcmanager.service.HousesHoldInfo2Manager;
import com.smcs.idcmanager.service.HousesHoldInfoManager;
import com.smcs.idcmanager.service.IdcManager;
import com.smcs.idcmanager.service.IdcUserInfoManager;
import com.smcs.idcmanager.service.Idc_manager_userManager;
import com.smcs.idcmanager.service.IpsegInfoManager;
import com.smcs.idcmanager.service.ServiceInfoManager;
import com.smcs.utils.Dom4jConverter;
import com.smcs.utils.EnumerationUtils;
import com.smcs.xmloper.commonData.DeleteData;
import com.smcs.xmloper.commonData.DeleteHouse;
import com.smcs.xmloper.commonData.DeleteInfo;
import com.smcs.xmloper.commonData.DeleteService;
import com.smcs.xmloper.commonData.DeleteUser;
import com.smcs.xmloper.commonData.UploadData;
import com.smcs.xmloper.commonData.UploadDataXmlOper;

public class IdcManagerImpl extends ManagerImpl implements IdcManager {

	protected void preSaveObject(Object obj) {
		super.preSaveObject(obj);

	}

	protected void postSaveObject(Object obj) {
		super.postSaveObject(obj);

	}

	protected void preRemoveObject(Object obj) {
		super.preRemoveObject(obj);

	}

	protected void postRemoveObject(Object obj) {
		super.postRemoveObject(obj);

	}

	public void saveIdc(Idc idc) {
		saveObject(idc);

	}

	public void removeIdcById(Integer id) {
		removeObjectById(id);

	}

	public Idc getIdcById(Integer id) {
		return (Idc) getObjectById(id);
	}

	public List<Idc> getIdcList(PageInfo pageInfo) {
		return super.getList(pageInfo);
	}

	public void saveSecurityIdc(Idc idc) {
		saveObject(idc);

	}

	public void removeSecurityIdcById(Integer id) {
		removeObjectById(id);

	}

	public Idc getSecurityIdcById(Integer id) {
		return (Idc) getObjectById(id);
	}

	public List<Idc> getSecurityIdcList(PageInfo pageInfo) {
		return super.getList(pageInfo);
	}

	public void saveOrUpdate(Idc idc) {
		IdcDAO idcDAO = (IdcDAO) getDAO();
		idcDAO.saveOrUpdate(idc);
	}

	public List<Object> getObjsByIdcid(Class clazz, String keys, String vals) {
		IdcDAO idcDAO = (IdcDAO) getDAO();
		return idcDAO.getObjsByIdcid(clazz, keys, vals);
	}

	public void saveCommonData(String xmlString) throws Exception {
		xmlString = Dom4jConverter.updateXmlElement(xmlString);

		UploadData uploadData = UploadDataXmlOper.parseIdcUserInfo(xmlString);
		IdcManager idcMgr = new IdcManagerImpl();
		// Idc_manager_userManager idc_manager_userMgr = new
		// Idc_manager_userManagerImpl();
		HouseInfoManager houseInfoMgr = new HouseInfoManagerImpl();
		GatewayInfoManager gatewayInfoMgr = new GatewayInfoManagerImpl();
		IpsegInfoManager ipsegInfoMgr = new IpsegInfoManagerImpl();
		IdcUserInfoManager idcUserInfoMgr = new IdcUserInfoManagerImpl();
		HousesHoldInfo2Manager housesHoldInfo2Mgr = new HousesHoldInfo2ManagerImpl();
		ServiceInfoManager serviceInfoMgr = new ServiceInfoManagerImpl();
		DomainManager domainMgr = new DomainManagerImpl();
		HousesHoldInfoManager HousesHoldInfoMgr = new HousesHoldInfoManagerImpl();

		IdcDAO idcDAO = (IdcDAO) getDAO();

		/************************************************** 新增信息 ***********************************************/
		// 新增节点
		if (uploadData != null && uploadData.getNewInfo() != null) {
			// 如果IDC单位需要添加，则添加
			String idcID = uploadData.getNewInfo().getIdcId();
			if (isNotNull(uploadData.getNewInfo().getIdcAdd())  //
				&& isNotNull(uploadData.getNewInfo().getIdcName()) //
				&& isNotNull(uploadData.getNewInfo().getIdcZip()) //
				&& isNotNull(uploadData.getNewInfo().getCorp()) //
				&& uploadData.getNewInfo().getIdcOfficer() != null //
				&& uploadData.getNewInfo().getEmergencyContact() != null) {
				Idc idc = new Idc();

				Idc_manager_user emergency = uploadData.getNewInfo().getEmergencyContact();
				if (emergency != null) {
					emergency.setVersion(0);
					emergency.setIdcID(idcID);
					String idType = emergency.getIdtype();
					String curIdType = new EnumerationUtils().getEnumIdByEnumVal("papersType", idType);
					emergency.setIdtype(curIdType);
				}

				Idc_manager_user officer = uploadData.getNewInfo().getIdcOfficer();
				if (officer != null) {
					officer.setVersion(0);
					officer.setIdcID(idcID);
					String idType = officer.getIdtype();
					String curIdType = new EnumerationUtils().getEnumIdByEnumVal("papersType", idType);
					officer.setIdtype(curIdType);
				}

				// 判断idcID是否存在，存在删除IDC
				Object target = idcDAO.getObjByIdcidAndId(Idc.class, new String[] { "idcID" }, new String[] { idcID });
				if (target != null) {
					Idc curIdc = (Idc) target;
					this.removeIdcById(curIdc.getId());
				}

				idc.setVersion(0);
				idc.setIdcID(idcID);
				idc.setIdcName(uploadData.getNewInfo().getIdcName());
				idc.setIdcAdd(uploadData.getNewInfo().getIdcAdd());
				idc.setIdcZip(uploadData.getNewInfo().getIdcZip());
				idc.setCorp(uploadData.getNewInfo().getCorp());
				idc.setIdcOfficer(officer);
				idc.setEmergencyContact(emergency);
				// 上报时间
				idc.setTimeStamp(uploadData.getTimeStamp());
				idcMgr.saveIdc(idc);
			}
			List<HouseInfo> houseInfos = uploadData.getNewInfo().getHouseInfos();
			List<IdcUserInfo> idcUserInfos = uploadData.getNewInfo().getIdcUserInfos();

			// 判断是否存在这个机房信息，1.有，不进行操作，2.没有，插入

			// 判断是否存在这个IDC/ISP用户信息，1.有，不进行操作，2.没有，插入

			if (houseInfos != null && houseInfos.size() > 0) {
				for (HouseInfo houseInfo : houseInfos) {
					if (houseInfo != null) {
						String houseId = houseInfo.getHouseID();// 对应IDC--主键
						// 查询数据库中是否存在这条记录，1.存在修改，2.不存在插入
						Object target = idcDAO.getObjByIdcidAndId(HouseInfo.class, new String[] { "houseID", "idcId" }, new String[] {
								houseId, idcID });
						if (target == null) {// 插入
							doAddOneHouseInfo(idcID, houseInfo, houseInfoMgr, null);
						} else {// 修改
								// 删除这个机房信息，重新插入
							HouseInfo curHouseInfo = (HouseInfo) target;
							houseInfoMgr.removeHouseInfoById(curHouseInfo.getId());

							doAddOneHouseInfo(idcID, houseInfo, houseInfoMgr, null);
						}
					}
				}
			}

			if (idcUserInfos != null && idcUserInfos.size() > 0) {
				for (IdcUserInfo idcUserInfo : idcUserInfos) {
					if (idcUserInfo != null) {
						String userInfoId = idcUserInfo.getIdckey();// 对应IDC--主键
						Object target = idcDAO.getObjByIdcidAndId(IdcUserInfo.class, new String[] { "idckey", "idcId" }, new String[] {
								userInfoId, idcID });
						if (target == null) {// 插入
							doAddOneUserInfo(idcID, idcUserInfo, idcUserInfoMgr);
						} else {// 修改
								// 删除这个机房的信息，重新插入
							IdcUserInfo curIdcUserInfo = (IdcUserInfo) target;
							idcUserInfoMgr.removeIdcUserInfoById(curIdcUserInfo.getId());

							doAddOneUserInfo(idcID, idcUserInfo, idcUserInfoMgr);
						}
					}
				}
			}
		}

		/******************************************** 更新信息 **************************************************/

		// 更新节点
		if (uploadData != null && uploadData.getUpdateInfo() != null) {
			System.out.println("==============================更新IDC经营单位信息===============================");
			// 如果IDC单位的信息需要更新，则更新idc经营单位的信息
			if (uploadData.getUpdateInfo().getIdcAdd() != null || uploadData.getUpdateInfo().getIdcName() != null
					|| uploadData.getUpdateInfo().getIdcZip() != null || uploadData.getUpdateInfo().getCorp() != null) {
				// 更新idc信息，先查询到该idc信息
				Idc idc = (Idc) idcMgr.getObject(Idc.class, "select * from idc where idcID = ?", uploadData.getUpdateInfo().getIdcId());
				if (idc != null && idc.getId() != null) { // 数据库中存在
					Idc_manager_user ftpIdcOfficer = uploadData.getUpdateInfo().getIdcOfficer();
					Idc_manager_user ftpEmergencyContact = uploadData.getUpdateInfo().getEmergencyContact();
					Idc_manager_user idcOfficer = idc.getIdcOfficer();
					Idc_manager_user emergencyContact = idc.getEmergencyContact();

					idcOfficer.setName(ftpIdcOfficer.getName());
					idcOfficer.setIdtype(new EnumerationUtils().getEnumIdByEnumVal("papersType", ftpIdcOfficer.getIdtype()));
					idcOfficer.setId_num(ftpIdcOfficer.getId_num());
					idcOfficer.setTel(ftpIdcOfficer.getTel());
					idcOfficer.setMobile(ftpIdcOfficer.getMobile());
					idcOfficer.setEmail(ftpIdcOfficer.getEmail());

					emergencyContact.setName(ftpEmergencyContact.getName());
					emergencyContact.setIdtype(new EnumerationUtils().getEnumIdByEnumVal("papersType", ftpEmergencyContact.getIdtype()));
					emergencyContact.setId_num(ftpEmergencyContact.getId_num());
					emergencyContact.setTel(ftpEmergencyContact.getTel());
					emergencyContact.setMobile(ftpEmergencyContact.getMobile());
					emergencyContact.setEmail(ftpEmergencyContact.getEmail());

					idc.setIdcName(uploadData.getUpdateInfo().getIdcName());
					idc.setIdcAdd(uploadData.getUpdateInfo().getIdcAdd());
					idc.setIdcZip(uploadData.getUpdateInfo().getIdcZip());
					idc.setCorp(uploadData.getUpdateInfo().getCorp());
					idc.setIdcOfficer(idcOfficer);
					idc.setEmergencyContact(emergencyContact);
					System.out.println("========================存储。。。。。。。。。。。。。。。。。");
					idcMgr.saveIdc(idc);
				}
			}
			// 若有更新机房、用户的节点，则更新
			if (uploadData.getUpdateInfo() != null && uploadData.getUpdateInfo().getUpdateData() != null) {
				// 更新机房信息
				String idcId = uploadData.getUpdateInfo().getIdcId();
				// 拿到ftp上报的机房信息
				List<HouseInfo> ftpHouseInfos = uploadData.getUpdateInfo().getUpdateData().getHouseInfos();
				// 拿到ftp上报的用户信息
				List<IdcUserInfo> ftpIdcUserInfos = uploadData.getUpdateInfo().getUpdateData().getIdcUserInfos();

				// 组装需要更新的机房信息
				if (ftpHouseInfos != null && ftpHouseInfos.size() > 0) {
					for (HouseInfo ftpHouseInfo : ftpHouseInfos) {
						if (ftpHouseInfo != null) {
							// 根据idcId和houseId,查询该机房并更新
							String sql = "select * from houseinfo where idcId = ? and houseID = ?";
							HouseInfo houseInfo = (HouseInfo) idcMgr.getObject(HouseInfo.class, sql, idcId, ftpHouseInfo.getHouseID());

							if (houseInfo != null) {
								// 若存在该机房信息，则更新
								Idc_manager_user ftpHouseOfficer = ftpHouseInfo.getHouseOfficer();
								Idc_manager_user houseOfficer = houseInfo.getHouseOfficer();

								houseOfficer.setName(ftpHouseOfficer.getName());
								houseOfficer.setIdtype(ftpHouseOfficer.getIdtype());
								houseOfficer.setId_num(ftpHouseOfficer.getId_num());
								houseOfficer.setTel(ftpHouseOfficer.getTel());
								houseOfficer.setMobile(ftpHouseOfficer.getMobile());
								houseOfficer.setEmail(ftpHouseOfficer.getEmail());

								houseOfficer.setId(houseInfo.getHouseOfficer().getId());
								houseInfo.setHouseName(ftpHouseInfo.getHouseName());
								houseInfo.setHouseType(ftpHouseInfo.getHouseType());
								houseInfo.setHouseProvince(ftpHouseInfo.getHouseProvince());
								houseInfo.setHouseCity(ftpHouseInfo.getHouseCity());
								houseInfo.setHouseCounty(ftpHouseInfo.getHouseCounty());
								houseInfo.setHouseAdd(ftpHouseInfo.getHouseAdd());
								houseInfo.setHouseZip(ftpHouseInfo.getHouseZip());
								houseInfo.setHouseOfficer(houseOfficer);

								// 遍历gateWay信息
								List<GatewayInfo> newGateWayInfoList = getGateWayInfo(ftpHouseInfo, idcMgr, idcId);
								if (newGateWayInfoList != null) {
									houseInfo.setGatewayInfos(newGateWayInfoList);
								}

								// 遍历ipSegInfo信息
								List<IpsegInfo> newIpSegInfoList = getIpSegInfoList(ftpHouseInfo, idcMgr, idcId);
								if (newIpSegInfoList != null && newIpSegInfoList.size() > 0) {
									houseInfo.setIpsegInfos(newIpSegInfoList);
								}
								// 更新机房信息
								doAddOneHouseInfo(idcId, houseInfo, houseInfoMgr, null);
							}
						}
					}
				}

				// 更新用户的所有信息
				if (ftpIdcUserInfos != null && ftpIdcUserInfos.size() > 0) {
					for (IdcUserInfo ftpIdcUserInfo : ftpIdcUserInfos) {
						// 通过idcId和userInfoId，查询该userInfo对象
						String sql4 = "select * from idcuserinfo where idcID = ? and idckey = ?";
						IdcUserInfo idcUserInfo = (IdcUserInfo) idcMgr
								.getObject(IdcUserInfo.class, sql4, idcId, ftpIdcUserInfo.getIdckey());

						/*********** 电信研究院版本 ***********/
						if (idcUserInfo != null && idcUserInfo.getId() != null) {// 删除这个用户的信息
							idcUserInfoMgr.removeIdcUserInfoById(idcUserInfo.getId());
						}
						doAddOneUserInfo(idcId, ftpIdcUserInfo, idcUserInfoMgr);

						/*********** 电信研究院版本 ***********/

						/***************
						 * 成林版本***************** //提供服务用户
						 * if(ftpIdcUserInfo.getServiceUsers() != null &&
						 * ftpIdcUserInfo.getServiceUsers().size() > 0){
						 * if(idcUserInfo != null){ //遍历数据库中用户信息，若是提供服务用户，更新用户
						 * List<ServiceUser> newServiceUserList =
						 * getServiceUserList(ftpIdcUserInfo, idcMgr, idcId,
						 * idcUserInfo); if(newServiceUserList != null &&
						 * newServiceUserList.size() > 0){
						 * idcUserInfo.setServiceUsers(newServiceUserList); } }
						 * }
						 * 
						 * //其他用户 if(ftpIdcUserInfo.getOtherUsers() != null &&
						 * ftpIdcUserInfo.getOtherUsers().size() > 0){
						 * //遍历数据库中用户信息，若是其他用户，更新用户 if(idcUserInfo != null){
						 * //遍历数据库中用户信息，若是提供服务用户，更新用户 List<OtherUser>
						 * newOtherUserList = getOtherUserList(ftpIdcUserInfo,
						 * idcMgr, idcId, idcUserInfo); if(newOtherUserList !=
						 * null && newOtherUserList.size() > 0){
						 * idcUserInfo.setOtherUsers(newOtherUserList); } } }
						 * //更新用户信息 doAddOneUserInfo(idcId, idcUserInfo,
						 * idcUserInfoMgr); 成林版本
						 ******************/
					}
				}
			}
		}

		/*********************************************** 删除节点 ************************************************/

		// 删除节点
		if (uploadData != null && uploadData.getDeleteInfo() != null && uploadData.getDeleteInfo().getDeleteDatas() != null) {
			DeleteInfo deleteInfo = uploadData.getDeleteInfo();
			DeleteData deleteData = deleteInfo.getDeleteDatas();

			String idcID = deleteInfo.getIdcId();
			if (deleteData != null) {
				DeleteHouse deleteHouse = deleteData.getHouse();
				DeleteUser deleteUser = deleteData.getUser();

				// 如果机房信息和用户信息都为空，则删除整个idc
				if (deleteHouse == null && deleteUser == null) {
					Idc idc = (Idc) idcMgr.getObject(Idc.class, "select * from idc where idcID = ?", idcID);
					if (idc != null) {
						idcMgr.removeIdcById(idc.getId());
					}

					// 查询所有的机房信息，并删除
					String sql1 = "select * from houseinfo where idcId = ?";
					List<HouseInfo> houseInfoList = (List<HouseInfo>) idcMgr.getListWithSql(HouseInfo.class, sql1, idcID);
					if (houseInfoList != null && houseInfoList.size() > 0) {
						for (HouseInfo curHouseInfo : houseInfoList) {
							houseInfoMgr.removeHouseInfoById(curHouseInfo.getId());
						}
					}

					// 删除所有的用户信息
					String sql2 = "select * from idcuserinfo where idcId = ?";
					List<IdcUserInfo> idcUserInfoList = (List<IdcUserInfo>) idcMgr.getListWithSql(IdcUserInfo.class, sql2, idcID);
					if (idcUserInfoList != null && idcUserInfoList.size() > 0) {
						for (IdcUserInfo curIdcUserInfo : idcUserInfoList) {
							idcUserInfoMgr.removeIdcUserInfoById(curIdcUserInfo.getId());
						}
					}
				}

				// 机房信息
				if (deleteHouse != null) {
					String houseId = deleteHouse.getHouseID().toString();
					if (!isNull(houseId)) {
						String gatewayId = null;
						String ipsegId = null;
						// 互联网出入口信息
						if (deleteHouse.getGatewayID() != null && deleteHouse.getGatewayID().size() > 0) {
							gatewayId = deleteHouse.getGatewayID().get(0).toString();
						}
						// IP地址段信息
						if (deleteHouse.getIpsegID() != null && deleteHouse.getIpsegID().size() > 0) {
							ipsegId = deleteHouse.getIpsegID().get(0).toString();
						}

						if (isNull(gatewayId) && isNull(ipsegId)) {// 删除机房信息
							Object target = idcDAO.getObjByIdcidAndId(HouseInfo.class, new String[] { "houseID", "idcId" }, new String[] {
									houseId, idcID });
							if (target != null) {
								HouseInfo curHouseInfo = (HouseInfo) target;
								houseInfoMgr.removeHouseInfoById(curHouseInfo.getId());
							}
						} else if (!isNull(gatewayId) && isNull(ipsegId)) {// 删除互联网出入口信息
							Object target = idcDAO.getObjByIdcidAndId(GatewayInfo.class, new String[] { "gi_id", "idcID" }, new String[] {
									gatewayId, idcID });
							if (target != null) {
								GatewayInfo curGatewayInfo = (GatewayInfo) target;
								gatewayInfoMgr.removeGatewayInfoById(curGatewayInfo.getId());
							}
						} else if (isNull(gatewayId) && !isNull(ipsegId)) {// 删除IP地址段信息
							Object target = idcDAO.getObjByIdcidAndId(IpsegInfo.class, new String[] { "is_ID", "idcID" }, new String[] {
									ipsegId, idcID });
							if (target != null) {
								IpsegInfo curIpsegInfo = (IpsegInfo) target;
								ipsegInfoMgr.removeIpsegInfoById(curIpsegInfo.getId());
							}
						} else {
							Object target = idcDAO.getObjByIdcidAndId(GatewayInfo.class, new String[] { "gi_id", "idcID" }, new String[] {
									gatewayId, idcID });
							if (target != null) {
								GatewayInfo curGatewayInfo = (GatewayInfo) target;
								gatewayInfoMgr.removeGatewayInfoById(curGatewayInfo.getId());
							}
							Object target2 = idcDAO.getObjByIdcidAndId(IpsegInfo.class, new String[] { "is_ID", "idcID" }, new String[] {
									ipsegId, idcID });
							if (target != null) {
								IpsegInfo curIpsegInfo = (IpsegInfo) target2;
								ipsegInfoMgr.removeIpsegInfoById(curIpsegInfo.getId());
							}

						}
					}
				}

				// 用户信息
				if (deleteUser != null) {
					// 只存在userID时，删除idcUserInfo表
					String userId = deleteUser.getUserID();
					DeleteService deleteService = deleteUser.getService();
					String hhId = deleteUser.getHhID();
					if (!isNull(userId)) {
						if (isNull(hhId) && deleteService == null) {// 删除idcUserInfo表
							doDeleteOneUserInfo(idcDAO, idcUserInfoMgr, userId, idcID);
						} else if (isNull(hhId)
								&& (isNull(deleteService.getServiceID()) && isNull(deleteService.getDomainID()) && isNull(deleteService
										.getHhID()))) {
							// 删除idUserInfo
							doDeleteOneUserInfo(idcDAO, idcUserInfoMgr, userId, idcID);
						} else if (!isNull(hhId)) {// 删除其他用户占用机房信息
							Object target = idcDAO.getObjByIdcidAndId(HousesHoldInfo2.class, new String[] { "hhID", "idcID" },
									new String[] { hhId, idcID });
							if (target != null) {
								HousesHoldInfo2 curHousesHoldInfo2 = (HousesHoldInfo2) target;
								housesHoldInfo2Mgr.removeHousesHoldInfo2ById(curHousesHoldInfo2.getId());
							}
						} else {// 删除服务信息
							if (!isNull(deleteService.getDomainID())) {
								Object target = idcDAO.getObjByIdcidAndId(Domain.class, new String[] { "idckey", "idcID" }, new String[] {
										deleteService.getDomainID(), idcID });
								if (target != null) {
									Domain curDomain = (Domain) target;
									domainMgr.removeDomainById(curDomain.getId());
								}
							} else if (!isNull(deleteService.getHhID())) {
								Object target = idcDAO.getObjByIdcidAndId(HousesHoldInfo.class, new String[] { "hhID", "idcID" },
										new String[] { deleteService.getHhID(), idcID });
								if (target != null) {
									HousesHoldInfo curHousesHoldInfo = (HousesHoldInfo) target;
									HousesHoldInfoMgr.removeHousesHoldInfoById(curHousesHoldInfo.getId());
								}
							} else if (!isNull(deleteService.getServiceID())) {
								Object target = idcDAO.getObjByIdcidAndId(ServiceInfo.class, new String[] { "serviceID", "idcID" },
										new String[] { deleteService.getServiceID(), idcID });
								if (target != null) {
									ServiceInfo curServiceInfo = (ServiceInfo) target;
									serviceInfoMgr.removeServiceInfoById(curServiceInfo.getId());
								}
							}

						}// 其他用户占用机房信息、服务信息同时存在<不存在>
					}
				}
			}
		}
	}

	/**
	 * 更新时，组装GateWayInfo
	 */
	public List<GatewayInfo> getGateWayInfo(HouseInfo ftpHouseInfo, IdcManager idcMgr, String idcId) {
		if (ftpHouseInfo.getGatewayInfos() != null && ftpHouseInfo.getGatewayInfos().size() > 0) {
			List<GatewayInfo> ftpGatewayInfos = ftpHouseInfo.getGatewayInfos();
			List<GatewayInfo> newGatewayInfos = new ArrayList<GatewayInfo>();
			if (ftpGatewayInfos != null && ftpGatewayInfos.size() > 0) {
				for (GatewayInfo ftpGatewayInfo : ftpGatewayInfos) {

					// 根据idcId和机房中的gateWayId,查询gateWay信息，并更新
					String sql2 = "select * from gatewayinfo where idcID = ? and gi_id = ?";
					GatewayInfo gatewayInfo = (GatewayInfo) idcMgr.getObject(GatewayInfo.class, sql2, idcId, ftpGatewayInfo.getGi_id());
					if (gatewayInfo != null) {// 修改互联网出入口信息
						gatewayInfo.setGi_id(ftpGatewayInfo.getGi_id());
						gatewayInfo.setBandWidth(ftpGatewayInfo.getBandWidth());
						gatewayInfo.setGatewayIP(ftpGatewayInfo.getGatewayIP());
						newGatewayInfos.add(gatewayInfo);
					} else {// 新增互联网出入口信息
						newGatewayInfos.add(ftpGatewayInfo);
					}
				}
				if (newGatewayInfos != null && newGatewayInfos.size() > 0) {
					return newGatewayInfos;
				}
			}
		}
		return null;
	}

	/**
	 * 更新时，组装ipSegInfo信息
	 */
	public List<IpsegInfo> getIpSegInfoList(HouseInfo ftpHouseInfo, IdcManager idcMgr, String idcId) {
		if (ftpHouseInfo.getIpsegInfos() != null && ftpHouseInfo.getIpsegInfos().size() > 0) {
			List<IpsegInfo> ftpIpsegInfos = ftpHouseInfo.getIpsegInfos();
			if (ftpIpsegInfos != null && ftpIpsegInfos.size() > 0) {
				List<IpsegInfo> newIpsegInfos = new ArrayList<IpsegInfo>();
				for (IpsegInfo ftpIpsegInfo : ftpIpsegInfos) {
					// 根据idcId和ipsegId，查询ipSegInfo信息
					String sql3 = "select * from ipseginfo where idcID = ? and is_ID = ?";
					IpsegInfo ipsegInfo = (IpsegInfo) idcMgr.getObject(IpsegInfo.class, sql3, idcId, ftpIpsegInfo.getIs_ID());

					if (ipsegInfo != null) {// 如果存在，则更新
						ipsegInfo.setIs_ID(ftpIpsegInfo.getIs_ID());
						ipsegInfo.setStartIP(ftpIpsegInfo.getStartIP());
						ipsegInfo.setEndIP(ftpIpsegInfo.getEndIP());
						ipsegInfo.setType(ftpIpsegInfo.getType());
						ipsegInfo.setUser_info(ftpIpsegInfo.getUser_info());
						ipsegInfo.setIdtype(ftpIpsegInfo.getIdtype());
						ipsegInfo.setIdnumber(ftpIpsegInfo.getIdnumber());
						ipsegInfo.setUseTime(ftpIpsegInfo.getUseTime());
						newIpsegInfos.add(ipsegInfo);
					} else {// 执行新增操作
						newIpsegInfos.add(ftpIpsegInfo);
					}
				}
				if (newIpsegInfos != null && newIpsegInfos.size() > 0) {
					return newIpsegInfos;
				}
			}
		}
		return null;
	}

	/**
	 * 更新时，组装ServiceUser
	 */
	public List<ServiceUser> getServiceUserList(IdcUserInfo ftpIdcUserInfo, IdcManager idcMgr, String idcId, IdcUserInfo idcUserInfo) {
		List<ServiceUser> ftpServiceUsers = ftpIdcUserInfo.getServiceUsers();
		if (ftpServiceUsers != null && ftpServiceUsers.size() > 0) {
			List<ServiceUser> newServiceUsers = new ArrayList<ServiceUser>();
			// 遍历所有的服务用户
			for (ServiceUser ftpServiceUser : ftpServiceUsers) {
				// 根据idcId和serviceUserId，查询该对象
				String sql5 = "select * from serviceuser where idcUserInfo = ?";
				ServiceUser serviceUser = (ServiceUser) idcMgr.getObject(ServiceUser.class, sql5, idcUserInfo.getId());
				// 遍历所有的提供服务
				if (serviceUser != null) {
					Idc_manager_user ftpOfficer = ftpServiceUser.getOfficer();
					Idc_manager_user officer = serviceUser.getOfficer();

					officer.setName(ftpOfficer.getName());
					officer.setIdtype(ftpOfficer.getIdtype());
					officer.setId_num(ftpOfficer.getId_num());
					officer.setTel(ftpOfficer.getTel());
					officer.setMobile(ftpOfficer.getMobile());
					officer.setEmail(ftpOfficer.getEmail());

					serviceUser.setUnitName(ftpServiceUser.getUnitName());
					serviceUser.setUnitNature(ftpServiceUser.getUnitNature());
					serviceUser.setIdtype(ftpServiceUser.getIdtype());
					serviceUser.setIdnumber(ftpServiceUser.getIdnumber());
					serviceUser.setOfficer(officer);
					serviceUser.setAddress(ftpServiceUser.getAddress());
					serviceUser.setZipCode(ftpServiceUser.getZipCode());

					// 查询出该提供服务用户所提供的服务
					List<ServiceInfo> newServiceInfoList = getServiceInfoList(ftpServiceUser, idcMgr, idcId);
					if (newServiceInfoList != null) {
						serviceUser.setServiceInfos(newServiceInfoList);
					}
					newServiceUsers.add(serviceUser);
				}
			}
			if (newServiceUsers != null && newServiceUsers.size() > 0) {
				return newServiceUsers;
			}
		}
		return null;
	}

	/**
	 * 更新时，组装serviceInfo
	 */
	public List<ServiceInfo> getServiceInfoList(ServiceUser ftpServiceUser, IdcManager idcMgr, String idcId) {
		if (ftpServiceUser.getServiceInfos() != null && ftpServiceUser.getServiceInfos().size() > 0) {
			List<ServiceInfo> newServiceInfos = new ArrayList<ServiceInfo>();
			List<ServiceInfo> ftpServiceInfos = ftpServiceUser.getServiceInfos();
			for (ServiceInfo ftpServiceInfo : ftpServiceInfos) {
				// 根据idcId和serviceInfoId，查询serviceInfo对象
				String sql6 = "select * from serviceinfo where idcID = ? and serviceID = ?";
				ServiceInfo serviceInfo = (ServiceInfo) idcMgr.getObject(ServiceInfo.class, sql6, idcId, ftpServiceInfo.getServiceID());

				List<ServiceContent> serviceContents = serviceInfo.getServiceContents();
				List<ServiceContent> ftpServiceContents = ftpServiceInfo.getServiceContents();
				for (int i = 0; i < ftpServiceContents.size(); i++) {
					ServiceContent ftpServiceContent = ftpServiceContents.get(i);
					serviceContents.get(i).setServiceContent(ftpServiceContent.getServiceContent());
				}
				serviceInfo.setRegType(ftpServiceInfo.getRegType());
				serviceInfo.setRegID(ftpServiceInfo.getRegID());
				serviceInfo.setSetMode(ftpServiceInfo.getSetMode());

				if (serviceInfo != null) {
					// 遍历所有的domain信息
					List<Domain> newDomainList = getDomainList(ftpServiceInfo, idcMgr, idcId);
					if (newDomainList != null) {
						serviceInfo.setDomains(newDomainList);
					}
					// 遍历所有的housesHoldInfo信息
					List<HousesHoldInfo> newHousesHoldInfos = getHousesHoldInfoList(ftpServiceInfo, idcMgr, idcId);
					if (newHousesHoldInfos != null) {
						serviceInfo.setHousesHoldInfos(newHousesHoldInfos);
					}
					newServiceInfos.add(serviceInfo);
				}
			}
			if (newServiceInfos != null && newServiceInfos.size() > 0) {
				return newServiceInfos;
			}
		}
		return null;
	}

	/**
	 * 更新时，组装domain信息
	 */
	public List<Domain> getDomainList(ServiceInfo ftpServiceInfo, IdcManager idcMgr, String idcId) {
		if (ftpServiceInfo.getDomains() != null && ftpServiceInfo.getDomains().size() > 0) {
			List<Domain> ftpDamains = ftpServiceInfo.getDomains();
			List<Domain> newDamains = new ArrayList<Domain>();
			if (ftpDamains != null && ftpDamains.size() > 0) {
				for (Domain ftpDomain : ftpDamains) {
					// 通过idcId和domainId,查询domain对象
					String sql = "select * from domain where idcID = ? and idckey = ?";
					Domain domain = (Domain) idcMgr.getObject(Domain.class, sql, idcId, ftpDomain.getIdckey());
					if (domain != null) {
						domain.setDomainName(ftpDomain.getDomainName());
						newDamains.add(domain);
					}
				}
				if (newDamains != null && newDamains.size() > 0) {
					return newDamains;
				}
			}
		}
		return null;
	}

	/**
	 * 更新时，组装HouseHoldInfo
	 */
	public List<HousesHoldInfo> getHousesHoldInfoList(ServiceInfo ftpServiceInfo, IdcManager idcMgr, String idcId) {
		if (ftpServiceInfo.getHousesHoldInfos() != null && ftpServiceInfo.getHousesHoldInfos().size() > 0) {
			List<HousesHoldInfo> newHousesHoldInfos = new ArrayList<HousesHoldInfo>();
			List<HousesHoldInfo> ftpHousesHoldInfos = ftpServiceInfo.getHousesHoldInfos();
			if (ftpHousesHoldInfos != null && ftpHousesHoldInfos.size() > 0) {
				for (HousesHoldInfo ftpHousesHoldInfo : ftpHousesHoldInfos) {
					// 根据idcId和houseHoldInfoId，查询对象
					String sql7 = "select * from housesholdinfo where idcID = ? and hhID = ?";
					HousesHoldInfo housesHoldInfo = (HousesHoldInfo) idcMgr.getObject(HousesHoldInfo.class, sql7, idcId,
							ftpHousesHoldInfo.getHhID());
					if (housesHoldInfo != null) {
						housesHoldInfo.setDistributeTime(ftpHousesHoldInfo.getDistributeTime());
						housesHoldInfo.setBandWidth(ftpHousesHoldInfo.getBandWidth());
					}
					// 遍历所有的ipTrans
					List<Iptrans> ipTransList = getIptransList(ftpHousesHoldInfo, idcMgr, idcId, housesHoldInfo);
					if (ipTransList != null) {
						housesHoldInfo.setIptranss(ipTransList);
						newHousesHoldInfos.add(housesHoldInfo);
					}
				}
				return newHousesHoldInfos;
			}
		}
		return null;
	}

	/**
	 * 更新时，组装iptrans
	 */
	public List<Iptrans> getIptransList(HousesHoldInfo ftpHousesHoldInfo, IdcManager idcMgr, String idcId, HousesHoldInfo housesHoldInfo) {
		if (ftpHousesHoldInfo.getIptranss() != null && ftpHousesHoldInfo.getIptranss().size() > 0) {
			List<Iptrans> newIptranss = new ArrayList<Iptrans>();
			List<Iptrans> ftpIptranss = ftpHousesHoldInfo.getIptranss();
			for (Iptrans ftpIptrans : ftpIptranss) {
				String sql8 = "select * from iptrans where idcID = ? and holdhhID = ?";
				Iptrans iptrans = (Iptrans) idcMgr.getObject(Iptrans.class, sql8, idcId, housesHoldInfo.getId());

				// 遍历所有的internetip
				if (iptrans != null) {
					List<InternetIp> ftpInternetIps = ftpIptrans.getInternetIps();
					if (ftpInternetIps != null) {
						List<InternetIp> newInternetIps = new ArrayList<InternetIp>();
						for (InternetIp ftpInternetIp : ftpInternetIps) {
							// 查询internetip对象
							String sql9 = "select * from internetip where idcID = ? and iptrans = ?";
							InternetIp internetIp = (InternetIp) idcMgr.getObject(InternetIp.class, sql9, idcId, iptrans.getId());
							if (internetIp != null) {
								internetIp.setStartIP(ftpInternetIp.getStartIP());
								internetIp.setEndIP(ftpInternetIp.getEndIP());
							}
							newInternetIps.add(internetIp);
						}
						iptrans.setInternetIps(newInternetIps);
					}

					// 遍历所有的netIp
					List<NetIp> ftpNetIps = ftpIptrans.getNetIps();
					if (ftpNetIps != null) {
						List<NetIp> newNetIps = new ArrayList<NetIp>();
						if (ftpNetIps != null) {
							for (NetIp ftpNetIp : ftpNetIps) {
								// 查询netIp对象
								String sql10 = "select * from netip where idcID = ? and iptrans = ?";
								NetIp netIp = (NetIp) idcMgr.getObject(NetIp.class, sql10, idcId, iptrans.getId());
								if (netIp != null) {
									netIp.setStartIP(ftpNetIp.getStartIP());
									netIp.setEndIP(ftpNetIp.getEndIP());
								}
								newNetIps.add(netIp);
							}
							iptrans.setNetIps(newNetIps);
						}
					}
				}
				newIptranss.add(iptrans);
			}
			if (newIptranss != null && newIptranss.size() > 0) {
				return newIptranss;
			}
		}
		return null;
	}

	/**
	 * 更新时，组装otherUser
	 */
	public List<OtherUser> getOtherUserList(IdcUserInfo ftpIdcUserInfo, IdcManager idcMgr, String idcId, IdcUserInfo idcUserInfo) {
		List<OtherUser> ftpOtherUsers = ftpIdcUserInfo.getOtherUsers();
		if (ftpOtherUsers != null && ftpOtherUsers.size() > 0) {
			List<OtherUser> newOtherUsers = new ArrayList<OtherUser>();
			// 遍历所有的服务用户
			for (OtherUser ftpOtherUser : ftpOtherUsers) {
				// 根据idcId和serviceUserId，查询该对象
				String sql5 = "select * from otheruser where idcUserInfo = ?";
				OtherUser otherUser = (OtherUser) idcMgr.getObject(OtherUser.class, sql5, idcUserInfo.getId());

				if (otherUser != null) {
					Idc_manager_user ftpOfficer = ftpOtherUser.getOfficer();
					Idc_manager_user officer = otherUser.getOfficer();

					officer.setName(ftpOfficer.getName());
					officer.setIdtype(ftpOfficer.getIdtype());
					officer.setId_num(ftpOfficer.getId_num());
					officer.setTel(ftpOfficer.getTel());
					officer.setMobile(ftpOfficer.getMobile());
					officer.setEmail(ftpOfficer.getEmail());

					otherUser.setUnitName(ftpOtherUser.getUnitName());
					otherUser.setUnitNature(ftpOtherUser.getUnitNature());
					otherUser.setIdtype(ftpOtherUser.getIdtype());
					otherUser.setIdnumber(ftpOtherUser.getIdnumber());
					otherUser.setOfficer(officer);
					otherUser.setAddress(ftpOtherUser.getAddress());
					otherUser.setZipCode(ftpOtherUser.getZipCode());

					// 查询出所有的houseHoldInfo2
					List<HousesHoldInfo2> newHouseHoldInfo2List = getHouseHoldInfo2List(ftpOtherUser, idcMgr, idcId);
					if (newHouseHoldInfo2List != null) {
						otherUser.setHousesHoldInfo2s(newHouseHoldInfo2List);
					}
					newOtherUsers.add(otherUser);
				}
			}
			if (newOtherUsers != null && newOtherUsers.size() > 0) {
				return newOtherUsers;
			}
		}
		return null;
	}

	/**
	 * 更新时，查找所有其他用户占有机房信息
	 */
	public List<HousesHoldInfo2> getHouseHoldInfo2List(OtherUser ftpOtherUser, IdcManager idcMgr, String idcId) {
		if (ftpOtherUser.getHousesHoldInfo2s() != null && ftpOtherUser.getHousesHoldInfo2s().size() > 0) {
			List<HousesHoldInfo2> newHousesHoldInfos = new ArrayList<HousesHoldInfo2>();
			List<HousesHoldInfo2> ftpHousesHoldInfos = ftpOtherUser.getHousesHoldInfo2s();
			if (ftpHousesHoldInfos != null && ftpHousesHoldInfos.size() > 0) {
				for (HousesHoldInfo2 ftpHousesHoldInfo2 : ftpHousesHoldInfos) {
					// 根据idcId和houseHoldInfoId，查询对象
					String sql7 = "select * from housesholdinfo2 where idcID = ? and hhID = ?";
					HousesHoldInfo2 housesHoldInfo = (HousesHoldInfo2) idcMgr.getObject(HousesHoldInfo2.class, sql7, idcId,
							ftpHousesHoldInfo2.getHhID());
					if (housesHoldInfo != null) {
						housesHoldInfo.setDistributeTime(ftpHousesHoldInfo2.getDistributeTime());
						housesHoldInfo.setBandWidth(ftpHousesHoldInfo2.getBandWidth());
					}
					// 遍历所有的ipSeg
					List<Ipseg> ipSegList = getIpSegList(ftpHousesHoldInfo2, idcMgr, idcId, housesHoldInfo);
					if (ipSegList != null) {
						housesHoldInfo.setIpsegs(ipSegList);
						newHousesHoldInfos.add(housesHoldInfo);
					}
				}
				return newHousesHoldInfos;
			}
		}
		return null;
	}

	/**
	 * 更新时，得到所有的ipSeg信息
	 */
	public List<Ipseg> getIpSegList(HousesHoldInfo2 ftpHousesHoldInfo2, IdcManager idcMgr, String idcId, HousesHoldInfo2 housesHoldInfo2) {
		if (ftpHousesHoldInfo2.getIpsegs() != null && ftpHousesHoldInfo2.getIpsegs().size() > 0) {
			List<Ipseg> ftpIpsegs = ftpHousesHoldInfo2.getIpsegs();
			List<Ipseg> newIpsegs = new ArrayList<Ipseg>();
			// 遍历所有的Ipseg
			if (ftpIpsegs != null && ftpIpsegs.size() > 0) {
				for (Ipseg ftpIpseg : ftpIpsegs) {
					// 得到Ipseg对象
					String sql = "select * from ipseg where idcID = ? and housesHoldInfo2 = ?";
					Ipseg ipSeg = (Ipseg) idcMgr.getObject(Ipseg.class, sql, idcId, housesHoldInfo2.getId());
					if (ipSeg != null) {
						ipSeg.setStartIP(ftpIpseg.getStartIP());
						ipSeg.setEndIP(ftpIpseg.getEndIP());
					}
					newIpsegs.add(ipSeg);
				}
				if (newIpsegs != null && newIpsegs.size() > 0) {
					return newIpsegs;
				}
			}
		}
		return null;
	}

	/**
	 * 删除一个IDC/ISP用户信息
	 * 
	 * @param idcDAO
	 * @param idcUserInfoMgr
	 * @param userId
	 * @param idcID
	 */
	public void doDeleteOneUserInfo(IdcDAO idcDAO, IdcUserInfoManager idcUserInfoMgr, String userId, String idcID) {
		Object target = idcDAO.getObjByIdcidAndId(IdcUserInfo.class, new String[] { "idckey", "idcId" }, new String[] { userId, idcID });
		if (target != null) {
			IdcUserInfo curIdcUserInfo = (IdcUserInfo) target;
			idcUserInfoMgr.removeIdcUserInfoById(curIdcUserInfo.getId());
		}
	}

	/**
	 * 删除指定的IDC信息
	 * 
	 * @param idcDAO
	 * @param idcId
	 * @param idc_manager_userMgr
	 * @param idcUserInfoMgr
	 * @param houseInfoMgr
	 */
	public void doDeleteIdc(IdcDAO idcDAO, Idc idc, Idc_manager_userManager idc_manager_userMgr, IdcUserInfoManager idcUserInfoMgr,
			HouseInfoManager houseInfoMgr) {
		// 删除IDC/ISP用户信息
		if (idc != null && idc.getIdcUserInfoList() != null) {
			for (IdcUserInfo ftpIdcUserInfo : idc.getIdcUserInfoList()) {
				String sql4 = "select * from idcuserinfo where idcID = ? and idckey = ?";
				IdcUserInfo curIdcUserInfo = (IdcUserInfo) idcUserInfoMgr.getObject(IdcUserInfo.class, sql4, idc.getIdcID(),
						ftpIdcUserInfo.getIdckey());

				if (curIdcUserInfo != null && curIdcUserInfo.getId() != null) {
					idcUserInfoMgr.removeIdcUserInfoById(curIdcUserInfo.getId());
				}
			}
		}

		// 删除机房信息
		if (idc != null && idc.getHouseInfoList() != null) {
			for (HouseInfo ftpHouseInfo : idc.getHouseInfoList()) {
				String sql = "select * from houseinfo where idcId = ? and houseID = ?";
				HouseInfo curHouseInfo = (HouseInfo) houseInfoMgr
						.getObject(HouseInfo.class, sql, idc.getIdcID(), ftpHouseInfo.getHouseID());
				if (curHouseInfo != null && curHouseInfo.getId() != null) {
					houseInfoMgr.removeHouseInfoById(curHouseInfo.getId());
				}
			}
		}

		/*
		 * //删除IDC信息 Object idc = idcDAO.getObjByIdcidAndId(Idc.class, new
		 * String[]{"idcID"}, new String[]{idcId}); if(idc != null){ Idc curIdc
		 * = (Idc)idc; this.removeIdcById(curIdc.getId()); }
		 * 
		 * 
		 * //删除用户信息 List<Object> idcMagrInfos =
		 * idcDAO.getObjsByIdcid(Idc_manager_user.class, "idcID", idcId);
		 * if(idcMagrInfos != null && idcMagrInfos.size() > 0){ for (Object
		 * object : idcMagrInfos) { Idc_manager_user curIdcMagrUser =
		 * (Idc_manager_user)object;
		 * idc_manager_userMgr.removeIdc_manager_userById
		 * (curIdcMagrUser.getId()); } }
		 */
	}

	/**
	 * 保存一个机房信息
	 * 
	 * @param idcID
	 * @param houseInfo
	 * @param houseInfoMgr
	 */
	public void doAddOneHouseInfo(String idcID, HouseInfo houseInfo, HouseInfoManager houseInfoMgr, Integer house_id) {
		if (houseInfo != null) {
			IdcManager idcMgr = (IdcManager) SpringContextHolder.getBean(Idc.class);
			houseInfo.setIdcId(idcID);
			houseInfo.setIdc(idcMgr.getIdcByIdcID(idcID).getId());
			// 修改机房性质
			String houseType = houseInfo.getHouseType();
			String curHouseType = new EnumerationUtils().getEnumIdByEnumVal("machineRoom", houseType);
			houseInfo.setHouseType(curHouseType);

			// 设置机房--信息安全责任人
			Idc_manager_user houseOfficer = houseInfo.getHouseOfficer();
			if (houseOfficer != null) {
				houseOfficer.setIdcID(idcID);

				// 修改证件类型
				String idType = houseOfficer.getIdtype();
				String curIdType = new EnumerationUtils().getEnumIdByEnumVal("papersType", idType);
				houseOfficer.setIdtype(curIdType);
			}

			// 获得机房--互联网出入口信息
			List<GatewayInfo> gatewayInfos = houseInfo.getGatewayInfos();
			if (gatewayInfos != null && gatewayInfos.size() > 0) {
				for (GatewayInfo gatewayInfo : gatewayInfos) {
					if (gatewayInfo != null) {
						gatewayInfo.setIdcID(idcID);
					}
				}
			}

			// 获得机房--IP地址段信息
			List<IpsegInfo> ipsegInfos = houseInfo.getIpsegInfos();
			if (ipsegInfos != null && ipsegInfos.size() > 0) {
				for (IpsegInfo ipsegInfo : ipsegInfos) {
					if (ipsegInfo != null) {
						ipsegInfo.setIdcID(idcID);

						String type = ipsegInfo.getType();
						String curType = new EnumerationUtils().getEnumIdByEnumVal("ipType", type);
						ipsegInfo.setType(curType);

						String idType = ipsegInfo.getIdtype();
						String curIdType = new EnumerationUtils().getEnumIdByEnumVal("papersType", idType);
						ipsegInfo.setIdtype(curIdType);
					}
				}
			}
			if (house_id != null) {
				houseInfo.setId(house_id);
			}
			houseInfoMgr.saveObject(houseInfo);
		}
	}

	/**
	 * 添加机房信息
	 * 
	 * @param idcID
	 * @param houseInfos
	 * @param houseInfoMgr
	 */
	public void doAddHouseInfo(String idcID, List<HouseInfo> houseInfos, HouseInfoManager houseInfoMgr) {
		if (houseInfos != null && houseInfos.size() > 0) {
			for (HouseInfo houseInfo : houseInfos) {
				doAddOneHouseInfo(idcID, houseInfo, houseInfoMgr, null);
			}
		}
	}

	/**
	 * 添加一个IPC/ISP用户信息
	 * 
	 * @param idcID
	 * @param idcUserInfo
	 * @param idcUserInfoMgr
	 */
	public void doAddOneUserInfo(String idcID, IdcUserInfo idcUserInfo, IdcUserInfoManager idcUserInfoMgr) {
		if (idcUserInfo != null) {
			idcUserInfo.setIdcId(idcID);

			// 提供网络服务用户<一个用户信只有一个提供网络服务用户或者其他用户，因为：IDC侧用的现在用的是List，所以这里用了List>
			List<ServiceUser> serviceUsers = idcUserInfo.getServiceUsers();
			if (serviceUsers != null && serviceUsers.size() > 0) {
				for (ServiceUser serviceUser : serviceUsers) {
					serviceUser.setIdcID(idcID);

					String unitNature = serviceUser.getUnitNature();
					String curUnitNature = new EnumerationUtils().getEnumIdByEnumVal("unit", unitNature);
					serviceUser.setUnitNature(curUnitNature);

					String idType = serviceUser.getIdtype();
					String curIdType = new EnumerationUtils().getEnumIdByEnumVal("papersType", idType);
					serviceUser.setIdtype(curIdType);

					// 设置网络服务者--网络安全责任人
					if (serviceUser != null) {
						Idc_manager_user officer = serviceUser.getOfficer();
						if (officer != null) {
							String officerIdType = officer.getIdtype();
							String curOfficerIdType = new EnumerationUtils().getEnumIdByEnumVal("papersType", officerIdType);
							officer.setIdtype(curOfficerIdType);
							officer.setIdcID(idcID);
						}
					}

					// 获得服务信息
					List<ServiceInfo> serviceInfos = serviceUser.getServiceInfos();
					if (serviceInfos != null && serviceInfos.size() > 0) {
						for (ServiceInfo serviceInfo : serviceInfos) {

							// 获得每个服务信息
							if (serviceInfo != null) {
								serviceInfo.setIdcID(idcID);

								String regType = serviceInfo.getRegType();
								String curRegType = new EnumerationUtils().getEnumIdByEnumVal("websitebak", regType);
								serviceInfo.setRegType(curRegType);

								String setMode = serviceInfo.getSetMode();
								String curSetMode = new EnumerationUtils().getEnumIdByEnumVal("accessWay", setMode);
								serviceInfo.setSetMode(curSetMode);

								// 获得服务内容
								List<ServiceContent> serviceContents = serviceInfo.getServiceContents();
								if (serviceContents != null && serviceContents.size() > 0) {
									for (ServiceContent serviceContent : serviceContents) {
										serviceContent.setIdcID(idcID);

										Integer serviceCon = serviceContent.getServiceContent();
										if (serviceCon != null) {
											String curServiceCon = new EnumerationUtils().getEnumIdByEnumVal("serviceContent",
													serviceCon.toString());
											serviceContent.setServiceContent(Integer.valueOf(curServiceCon));
										}
									}
								}

								// 获得服务信息的域名
								List<Domain> domains = serviceInfo.getDomains();
								if (domains != null && domains.size() > 0) {
									for (Domain domain : domains) {
										domain.setIdcID(idcID);
									}
								}

								// 获得服务信息的服务用户占用机房信息
								List<HousesHoldInfo> housesHoldInfos = serviceInfo.getHousesHoldInfos();
								if (housesHoldInfos != null && housesHoldInfos.size() > 0) {
									// 获得每个服务用户占用机房信息
									for (HousesHoldInfo housesHoldInfo : housesHoldInfos) {
										housesHoldInfo.setIdcID(idcID);

										// 获得每个机房的IP转换信息,修改时修改将IP转换信息<共三个表>删掉重新插入
										List<Iptrans> iptrans = housesHoldInfo.getIptranss();
										if (iptrans != null && iptrans.size() > 0) {
											for (Iptrans curIptrans : iptrans) {
												if (curIptrans != null) {
													curIptrans.setIdcID(idcID);

													// 通过IP转换信息表获得互联网IP地址段
													List<InternetIp> internetIps = curIptrans.getInternetIps();
													if (internetIps != null && internetIps.size() > 0) {
														for (InternetIp internetIp : internetIps) {
															internetIp.setIdcID(idcID);
														}
													}

													// 通过IP转换信息表获得对应私网IP地址段
													List<NetIp> netIps = curIptrans.getNetIps();
													if (netIps != null && netIps.size() > 0) {
														for (NetIp netIp : netIps) {
															netIp.setIdcID(idcID);
														}
													}
												}
											}
										}
									}
								}
							}
						}
					}
				}
			}

			// 其它用户<一个用户信只有一个提供网络服务用户或者其他用户，因为：IDC侧用的现在用的是List，所以这里用了List>
			List<OtherUser> otherUsers = idcUserInfo.getOtherUsers();
			if (otherUsers != null && otherUsers.size() > 0) {
				for (OtherUser otherUser : otherUsers) {
					otherUser.setIdcID(idcID);

					String unitNature = otherUser.getUnitNature();
					String curUnitNature = new EnumerationUtils().getEnumIdByEnumVal("unit", unitNature);
					otherUser.setUnitNature(curUnitNature);

					String idType = otherUser.getIdtype();
					String curIdType = new EnumerationUtils().getEnumIdByEnumVal("papersType", idType);
					otherUser.setIdtype(curIdType);

					// 其它用户-网络安全责任人
					if (otherUser != null) {
						Idc_manager_user officer = otherUser.getOfficer();
						if (officer != null) {
							String officerIdType = officer.getIdtype();
							String curOfficerIdType = new EnumerationUtils().getEnumIdByEnumVal("papersType", officerIdType);
							officer.setIdtype(curOfficerIdType);
							officer.setIdcID(idcID);
						}
					}

					// 获得其他用户占用机房信息
					List<HousesHoldInfo2> HousesHoldInfo2s = otherUser.getHousesHoldInfo2s();
					if (HousesHoldInfo2s != null && HousesHoldInfo2s.size() > 0) {
						for (HousesHoldInfo2 housesHoldInfo2 : HousesHoldInfo2s) {
							housesHoldInfo2.setIdcID(idcID);

							// 获得IP地址段
							List<Ipseg> ipsegs = housesHoldInfo2.getIpsegs();
							if (ipsegs != null && ipsegs.size() > 0) {
								for (Ipseg ipseg : ipsegs) {
									ipseg.setIdcID(idcID);
								}
							}
						}
					}
				}
			}
			idcUserInfoMgr.saveObject(idcUserInfo);
		}

	}

	/**
	 * 添加IPC/ISP用户信息
	 * 
	 * @param idcID
	 * @param userInfos
	 * @param idcUserInfoMgr
	 */
	public void doAddUserInfo(String idcID, List<IdcUserInfo> userInfos, IdcUserInfoManager idcUserInfoMgr) {
		if (userInfos != null && userInfos.size() > 0) {
			for (IdcUserInfo idcUserInfo : userInfos) {
				doAddOneUserInfo(idcID, idcUserInfo, idcUserInfoMgr);
			}
		}

	}

	/**
	 * 执行管局侧下发指令的操作
	 * 
	 * @param uploadData
	 * @param houseInfoMgr
	 * @param idcUserInfoMgr
	 */
	public void doQuery(UploadData uploadData, HouseInfoManager houseInfoMgr, IdcUserInfoManager idcUserInfoMgr) {
		Idc idc = uploadData.getQueryResult().getIdcInfo();
		if (idc == null) {
			idc = uploadData.getQueryResult();
		}
		String idcID = idc.getIdcID();
		// 更新idc经营单位信息
		Idc curIdc = (Idc) idcUserInfoMgr.getObject(Idc.class, "select * from idc where idcID = ?", idcID);
		if (curIdc != null && curIdc.getId() != null) { // 数据库中存在
			Idc ftpIdc = idc;
			Idc_manager_user ftpIdcOfficer = ftpIdc.getIdcOfficer();
			Idc_manager_user ftpEmergencyContact = ftpIdc.getEmergencyContact();
			Idc_manager_user idcOfficer = curIdc.getIdcOfficer();
			Idc_manager_user emergencyContact = curIdc.getEmergencyContact();

			idcOfficer.setName(ftpIdcOfficer.getName());
			idcOfficer.setIdtype(new EnumerationUtils().getEnumIdByEnumVal("papersType", ftpIdcOfficer.getIdtype()));
			idcOfficer.setId_num(ftpIdcOfficer.getId_num());
			idcOfficer.setTel(ftpIdcOfficer.getTel());
			idcOfficer.setMobile(ftpIdcOfficer.getMobile());
			idcOfficer.setEmail(ftpIdcOfficer.getEmail());

			emergencyContact.setName(ftpEmergencyContact.getName());
			emergencyContact.setIdtype(new EnumerationUtils().getEnumIdByEnumVal("papersType", ftpEmergencyContact.getIdtype()));
			emergencyContact.setId_num(ftpEmergencyContact.getId_num());
			emergencyContact.setTel(ftpEmergencyContact.getTel());
			emergencyContact.setMobile(ftpEmergencyContact.getMobile());
			emergencyContact.setEmail(ftpEmergencyContact.getEmail());

			curIdc.setTimeStamp(uploadData.getTimeStamp());
			curIdc.setIdcName(ftpIdc.getIdcName());
			curIdc.setIdcAdd(ftpIdc.getIdcAdd());
			curIdc.setIdcZip(ftpIdc.getIdcZip());
			curIdc.setCorp(ftpIdc.getCorp());
			curIdc.setIdcOfficer(idcOfficer);
			curIdc.setEmergencyContact(emergencyContact);
			curIdc.setVersion(0);
			this.saveObject(curIdc);
		} else { // 插入
			Idc_manager_user emergency = idc.getEmergencyContact();
			if (emergency != null) {
				emergency.setIdcID(idcID);
				String idType = emergency.getIdtype();
				String curIdType = new EnumerationUtils().getEnumIdByEnumVal("papersType", idType);
				emergency.setIdtype(curIdType);
			}

			Idc_manager_user officer = idc.getIdcOfficer();
			if (officer != null) {
				officer.setIdcID(idcID);
				String idType = officer.getIdtype();
				String curIdType = new EnumerationUtils().getEnumIdByEnumVal("papersType", idType);
				officer.setIdtype(curIdType);
			}
			idc.setTimeStamp(uploadData.getTimeStamp());
			idc.setVersion(0);
			this.saveObject(idc);
		}

		// 设置机房信息
		if (idc != null && idc.getHouseInfoList() != null) {
			List<HouseInfo> houseInfos = idc.getHouseInfoList();
			doAddHouseInfo(idcID, houseInfos, houseInfoMgr);
		}

		// 设置用户信息
		if (idc != null && idc.getIdcUserInfoList() != null) {
			List<IdcUserInfo> userInfos = idc.getIdcUserInfoList();
			doAddUserInfo(idcID, userInfos, idcUserInfoMgr);
		}
	}

	public boolean isNotNull(String str) {
		return !isNull(str);
	}

	public boolean isNull(String str) {
		if (str == null) {
			return true;
		} else if ("".equals(str.trim())) {
			return true;
		}

		return false;
	}

	/**
	 * 通过idcID，查询idc
	 */
	public Idc getIdcByIdcID(String idcID) {
		String sql = "select * from idc where idcID = ?";
		List<Idc> list = (List<Idc>) super.getListWithSql(Idc.class, sql, idcID);
		if (list != null && list.size() > 0) {
			return list.get(0);
		}
		return null;
	}
}
